var1 = 'Hello World!'
var2 = "Python Runoob"

# 打印字符啊
print("var1[0]: ", var1[0])
# [] [1,3) 1 <= x < 3
print("var2[1:5]: ", var2[1:5])

var1 = 'Hello World!'
print("输出 :- ", var1[:6] + 'Runoob!')

# 列表
# !/usr/bin/python

list1 = ['physics', 'chemistry', 1997, 2000]
list2 = [1, 2, 3, 4, 5, 6, 7]

print("list1[0]: ", list1[0])
print("list2[1:5]: ", list2[1:5])

# 更新列表
list1 = []
list1.append("Google")
list1.append("apple")
print(list1)
# 删除列表元素
list1 = ['physics', 'chemistry', 1997, 2000]
print(list1)
del list1[2]
print("After deleting value at index 2 : ")
print(list1)

# 计算出现的次数
aList = [123, 'xyz', 'zara', 'abc', 123]
print("Count for 123 : ", aList.count(123))

# 将指定对象插入列表
aList = [123, 'xyz', 'zara', 'abc']
aList.insert(3, 2009)
print("Final List : ", aList)
# 移除对象
aList = [123, 'xyz', 'zara', 'abc', 'xyz']
aList.remove('xyz')
print("List : ", aList)
aList.remove('abc')
print("List : ", aList)
# 用于从列表中找出某个值第一个匹配项的索引位置。
aList = [123, 'xyz', 'runoob', 'abc']
print("xyz 索引位置: ", aList.index('xyz'))
print("runoob 索引位置 : ", aList.index('runoob', 1, 3))
# 排序
aList = ['123', 'Google', 'Runoob', 'Taobao', 'Facebook']
aList.sort()
print("List : ")
print(aList)

# 元组
# Python 的元组与列表类似，不同之处在于元组的元素不能修改。
# 元组使用小括号，列表使用方括号。
# 元组创建很简单，只需要在括号中添加元素，并使用逗号隔开即可。

# !/usr/bin/python

tup1 = ('physics', 'chemistry', 1997, 2000)
tup2 = (1, 2, 3, 4, 5, 6, 7)
print("tup1[0]: ", tup1[0])
print("tup2[1:5]: ", tup2[1:5])

# 字典 就是 key ： value
tinydict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print("tinydict['Name']: ", tinydict['Name'])
print("tinydict['Age']: ", tinydict['Age'])

# 修改字典
tinydict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
tinydict['Age'] = 8  # 更新
tinydict['School'] = "RUNOOB"  # 添加
print("tinydict['Age']: ", tinydict['Age'])
print("tinydict['School']: ", tinydict['School'])

tinydict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}

del tinydict['Name']  # 删除键是'Name'的条目
tinydict.clear()  # 清空字典所有条目
del tinydict  # 删除字典
try:
    print("tinydict['Age']: ", tinydict['Age'])
    print("tinydict['School']: ", tinydict['School'])
except Exception as e:
    print("有异常", e)

# 获取指定的key
tinydict = {'Name': 'Runoob', 'Age': 27}
print ("Age : %s" %  tinydict.get('Age'))


seq = ('Google', 'Runoob', 'Taobao')
# 不指定默认的键值，默认为 None
thisdict = dict.fromkeys(seq)
print("新字典为 : %s" % str(thisdict))
# 指定默认的键值
thisdict = dict.fromkeys(seq, 10)
print("新字典为 : %s" % str(thisdict))